#登录业务

import allure
#导入和该业务有关的N个页面类
from page.page_index import PageIndex
from page.page_login import PageLogin
from page.page_user import PageUser

class ServiceLogin(object):
    def __init__(self,driver):
        self.driver=driver
        #初始化UI1的页面对象
        self.page_index=PageIndex(self.driver)
        #初始化UI2的页面对象
        self.page_login=PageLogin(self.driver)
        #初始化UI3的页面对象
        self.page_user=PageUser(self.driver)

    @allure.severity("blocker")
    @allure.step(title="覆盖用例：K001/K007")
    def service_login_002(self,d):
        #UI1上的操作
        allure.attach("","步骤1：打开首页")
        self.page_index.openUrl()
        allure.attach("", "步骤2：点击首页上的登录按钮")
        self.page_index.click_login()
        #UI2上的操作
        allure.attach("", f"步骤3：输入账号{d['zanhao']}")
        self.page_login.input_zanhao(d["zanhao"])
        allure.attach("", f"步骤4：输入密码{d['pwd']}")
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_login()
        #UI3上的操作
        yuqi = d["yuqi"]
        siji=self.page_user.getNicenH2Text()
        fileName=self.page_user.savePng3("登录业务",d["key"]) #"登录业务_K001_20231129094615"
        allure.attach(open('./screen/' + fileName + '.png', 'rb').read(), "本次截图", allure.attachment_type.PNG)
        # 断言
        if yuqi == siji:
            return True
        else:
            return False


    def service_login_001(self,d):
        #UI1上的操作
        self.page_index.openUrl()
        self.page_index.click_login()
        #UI2上的操作
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_login()
        #UI3上的操作
        yuqi = d["yuqi"] #"invalid-text"
        siji=self.page_login.getPwdClass() #"xx invalid-text"
        return yuqi in siji


    def service_login_003(self,d):
        #UI1上的操作
        self.page_index.openUrl()
        self.page_index.click_login()
        #UI2上的操作
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_login()
        #UI3上的操作
        yuqi = d["yuqi"] #"错误"
        siji=self.page_login.getErrorTipText() #"账号或密码错误"
        return yuqi in siji


    def service_login_004(self,d):
        #UI1上的操作
        self.page_index.openUrl()
        self.page_index.click_login()
        #UI2上的操作
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_login()
        #UI3上的操作
        yuqi = d["yuqi"] #"invalid-text"
        siji=self.page_login.getZanhaoClass()
        return yuqi in siji
